package cn.iocoder.yudao.adminserver.modules.live.controller.projectPlanEvent;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;

import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.adminserver.modules.live.controller.projectPlanEvent.vo.*;
import cn.iocoder.yudao.adminserver.modules.live.dal.dataobject.projectPlanEvent.LiveProjectPlanEventDO;
import cn.iocoder.yudao.adminserver.modules.live.convert.projectPlanEvent.LiveProjectPlanEventConvert;
import cn.iocoder.yudao.adminserver.modules.live.service.projectPlanEvent.LiveProjectPlanEventService;

@Api(tags = "项目阶段事项")
@RestController
@RequestMapping("/live/project-plan-event")
@Validated
public class LiveProjectPlanEventController {

    @Resource
    private LiveProjectPlanEventService projectPlanEventService;

    @PostMapping("/create")
    @ApiOperation("创建项目阶段事项")
    @PreAuthorize("@ss.hasPermission('live:project-plan-event:create')")
    public CommonResult<Long> createProjectPlanEvent(@Valid @RequestBody LiveProjectPlanEventCreateReqVO createReqVO) {
        return success(projectPlanEventService.createProjectPlanEvent(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新项目阶段事项")
    @PreAuthorize("@ss.hasPermission('live:project-plan-event:update')")
    public CommonResult<Boolean> updateProjectPlanEvent(@Valid @RequestBody LiveProjectPlanEventUpdateReqVO updateReqVO) {
        projectPlanEventService.updateProjectPlanEvent(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除项目阶段事项")
    @ApiImplicitParam(name = "id", value = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('live:project-plan-event:delete')")
    public CommonResult<Boolean> deleteProjectPlanEvent(@RequestParam("id") Long id) {
        projectPlanEventService.deleteProjectPlanEvent(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得项目阶段事项")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('live:project-plan-event:query')")
    public CommonResult<LiveProjectPlanEventRespVO> getProjectPlanEvent(@RequestParam("id") Long id) {
        LiveProjectPlanEventDO projectPlanEvent = projectPlanEventService.getProjectPlanEvent(id);
        return success(LiveProjectPlanEventConvert.INSTANCE.convert(projectPlanEvent));
    }

    @GetMapping("/list")
    @ApiOperation("获得项目阶段事项列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('live:project-plan-event:query')")
    public CommonResult<List<LiveProjectPlanEventRespVO>> getProjectPlanEventList(@RequestParam("ids") Collection<Long> ids) {
        List<LiveProjectPlanEventDO> list = projectPlanEventService.getProjectPlanEventList(ids);
        return success(LiveProjectPlanEventConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得项目阶段事项分页")
    @PreAuthorize("@ss.hasPermission('live:project-plan-event:query')")
    public CommonResult<PageResult<LiveProjectPlanEventRespVO>> getProjectPlanEventPage(@Valid LiveProjectPlanEventPageReqVO pageVO) {
        PageResult<LiveProjectPlanEventDO> pageResult = projectPlanEventService.getProjectPlanEventPage(pageVO);
        return success(LiveProjectPlanEventConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出项目阶段事项 Excel")
    @PreAuthorize("@ss.hasPermission('live:project-plan-event:export')")
    @OperateLog(type = EXPORT)
    public void exportProjectPlanEventExcel(@Valid LiveProjectPlanEventExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<LiveProjectPlanEventDO> list = projectPlanEventService.getProjectPlanEventList(exportReqVO);
        // 导出 Excel
        List<LiveProjectPlanEventExcelVO> datas = LiveProjectPlanEventConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "项目阶段事项.xls", "数据", LiveProjectPlanEventExcelVO.class, datas);
    }

}
